package aole.visq.draw.undo;

import java.awt.image.BufferedImage;

import javax.swing.undo.AbstractUndoableEdit;

import aole.visq.draw.DrawApp;

public class UndoableKey extends AbstractUndoableEdit {
	private static final long	serialVersionUID	= 1L;
	private int					frame;
	private boolean				added;
	private DrawApp				app;
	private BufferedImage		img;

	public UndoableKey( DrawApp a, int f, boolean add ) {
		this( a, f, add, null );
	}

	public UndoableKey( DrawApp a, int f, boolean add, BufferedImage img ) {
		app = a;
		frame = f;
		added = add;
		this.img = img;
	}

	public void undo() {
		app.setCurrentFrame( frame );
		if( added )
			app.removeKey();
		else{ app.createKey();
			app.drawImage( img );
		}
	}

	public void redo() {
		app.setCurrentFrame( frame );
		if( added )
			app.createKey();
		else app.removeKey();
	}
}